package com.example.shixun.controller;

import com.example.shixun.service.AuthService;
import com.example.shixun.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
public class MailController {
    @Autowired
    private EmailService emailService;
    @Autowired
    private AuthService authService;
    @PostMapping("getEmailCode")
    @ResponseBody
    public String getCheckCode(@RequestBody Map<String, String> param){
        //String checkCode = String.valueOf(new Random().nextInt(899999) + 100000);
        //String message = "您的注册验证码为："+checkCode;
        try {
            System.out.println("getCheckCode Email:"+param.get("email"));
            authService.sendMailCode(param.get("email"));
        }catch (Exception e){
            return "";
        }
        return null;
    }
}